<template>
	<view class="content"
		:style="'background:#000 url(https://front.zhaocaiami.vworld365.com/imgs/11.jpg) no-repeat center top;background-size:100%;'">
		<view class="box">
			<view class="con">
				<input v-model="true_name" placeholder-class="placeholder" placeholder="请输入您的姓名" />
				<input v-model="phone" type="number" placeholder-class="placeholder" placeholder="请输入您的联系电话" />
				<view @click="toPost" class="button">提交</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: 0,
				img2: '',
				true_name: '',
				phone: '',
				mainid: '',
			}
		},
		onLoad(e) {
			let that = this;
			that.id = e.id;
			uni.getStorage({
				key: 'user',
				success: res => {
					this.mainid = res.data.id;
					console.log("openid: ", this.mainid);
				}
			})
			// that.id ='1421034640391622658';
			// common.request('user/ad_info', {id:e.id}, function (res) {
			// 	for (var x in res.data) { 
			// 		that[x] = res.data[x];
			// 	}
			// })
		},
		methods: {
			toPost() {
				let that = this;
				if (that.true_name == '') {
					this.toast('请输入您的姓名');
				} else if (that.phone == '') {
					this.toast('请输入您的联系电话');
				}
				if (!this.checkPhone(that.phone)) {
					this.toast("请输入正确手机号");
				} else {
					var infos = {
						"phone": that.phone,
						"name": that.true_name,
					};
					infos = JSON.stringify(infos);
					var data = {
						adId: that.id, //		广告ID		false			 string
						id: '', //		id		false			 string
						info: infos, //	信息		false			 string
						status: '', //	状态		false			 integer
						tradeId: '', //订单ID		false			 string
						userId: that.mainid, //	用户ID		false			 string
						verificationCode: '' //	验证码		false			 string
					}
					console.log("请求参数: ", data);
					this.$request.post(`ad/saveOrUpdateAdCollect`, data, 'json')
						.then(res => {
							console.log("收集信息 res:", res)
							this.toast('提交成功');
							setTimeout(function() {
								uni.navigateBack();
							}, 2000);
						}).catch(err => {
							console.log(" err:", err)
						})
				}
			},
			toast(msg) {
				uni.showToast({
					title: msg,
					icon: 'none',
					duration: 2000
				});
			},
			checkPhone(phone) {
				return /^1\d{10}$/.test(phone);
			}

		}
	}
</script>

<style>
	.content {
		background: no-repeat center top;
		background-size: 100%;
		height: 100vh;
	}

	.box {
		padding: 24upx;
		background-color: rgba(255, 255, 255, .4);
		position: fixed;
		left: 0;
		top: 80vw;
		width: 702upx;
		z-index: 1000;
	}

	.box .con {
		box-shadow: 0 0 3upx #999;
		padding: 24upx;
		background-color: #FFFFFF;
		border-radius: 10upx;
	}

	.box .con input {
		box-shadow: 0 0 3upx #999;
		height: 70upx;
		line-height: 70upx;
		text-align: center;
		font-size: 26upx;
		border: 0;
		border-radius: 35upx;
		margin-top: 20upx;
	}

	.box .con .button {
		background-color: #0e0b02;
		color: #e9ca70;
		height: 70upx;
		line-height: 70upx;
		text-align: center;
		font-size: 26upx;
		border-radius: 35upx;
		margin-top: 50upx;
	}
</style>
